#include <iostream>

int main(int argc, char *argv[])
{
    int n = 5; // The total number of elements to sort.
    int k = 10; // The total number of posible values of element. 
    int A[] = {4, 1, 3, 4, 3}; // The input array to sort.
    int C[10]; // Cache area.
    int B[n];
    for (int i = 0; i < k; i++)
	C[i] = 0;
    for (int j = 0; j < n; j++)  // Counting...
	C[A[j]] = C[A[j]] + 1;
    for (int i = 1; i < k; i++)  // To be stable...
	C[i] = C[i] + C[i - 1];
    for (int j = n - 1; j >= 0; j--)
    {
	B[C[A[j]] - 1] = A[j];
	C[A[j]] = C[A[j]] - 1;
    }
    std::cout << "B = [";
    for (int i = 0; i < n; i++)
	std::cout << B[i] << ", ";
    std::cout << "\b\b]" << std::endl;
    return 0;
};
